Caminatas Aleatorias¶

In [303]:
randomwalk(G=smallstar,pos=smallstarpos, title="Star graph")
Out[303]:
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [244]:
randomwalk(G=bigstar,pos=bigstarpos,title="Star graph")
Out[244]:
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [245]:
randomwalk(G=erdos,pos=erdospos, title=" Erdos-Renyi graph")
Out[245]:
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [306]:
randomwalk(G=hexa,pos=hexapos,title="Hexagonal grid")
Out[306]:
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [307]:
nx.pagerank(hexa,alpha=1)
Out[307]:
{(-2, 0, 2): 0.03571466181797872,
 (-2, 1, 1): 0.04761852180164461,
 (-2, 2, 0): 0.03571466181797872,
 (-1, -1, 2): 0.04761852180164461,
 (-1, 0, 1): 0.07142877772279567,
 (-1, 1, 0): 0.07142877772279568,
 (-1, 2, -1): 0.0476185218016446,
 (0, -2, 2): 0.035714661817978714,
 (0, -1, 1): 0.07142877772279567,
 (0, 0, 0): 0.07142823194548521,
 (0, 1, -1): 0.07142877772279568,
 (0, 2, -2): 0.035714661817978714,
 (1, -2, 1): 0.0476185218016446,
 (1, -1, 0): 0.07142877772279567,
 (1, 0, -1): 0.07142877772279567,
 (1, 1, -2): 0.0476185218016446,
 (2, -2, 0): 0.035714661817978714,
 (2, -1, -1): 0.0476185218016446,
 (2, 0, -2): 0.035714661817978714}
In [301]:
randomwalk(G=France,pos=Francepos,title="Francia",paintnodes=True)
Out[301]:
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
In [182]:
# Create a new graph object
G = nx.Graph()

# Add nodes (cities) with their latitude and longitude
cities = {
    "Paris": (48.8566, 2.3522),
    "Marseille": (43.2965, 5.3698),
    "Lyon": (45.7640, 4.8357),
    "Toulouse": (43.6047, 1.4442),
    "Nice": (43.7102, 7.2620),
    "Nantes": (47.2186, -1.5536),
    "Strasbourg": (48.5734, 7.7521),
    "Lille": (50.6292, 3.0573)
}
G.add_nodes_from(cities.keys())

# Add edges (train connections)
connections = [("Paris", "Marseille"), ("Paris", "Lyon"), ("Paris", "Toulouse"), 
               ("Paris", "Nantes"), ("Paris", "Strasbourg"), ("Paris", "Lille"),
               ("Lyon", "Marseille"), ("Lyon", "Toulouse"), ("Lyon", "Strasbourg"),
               ("Marseille", "Nice"), ("Toulouse", "Nantes")]

G.add_edges_from(connections)

# Draw the graph using latitude and longitude for positioning
nx.draw(G, cities, with_labels=True, node_size=2000, node_color="lightblue", font_size=10, font_color="black", font_weight="bold")
plt.title("Major Train Connections in France")
plt.show()
No description has been provided for this image
In [192]:
# Create a new graph object
G = nx.Graph()

# Add nodes (cities) with their latitude and longitude
cities = {
    "Paris": (2.3522, 48.8566),
    "Marseille": (5.3698, 43.2965),
    "Lyon": (4.8422, 45.7597),
    "Toulouse": (1.4442, 43.6047),
    "Nice": (7.2620, 43.7102),
    "Nantes": (-1.5536, 47.2184),
    "Strasbourg": (7.7521, 48.5734),
    "Lille": (3.0573, 50.6292)
}
G.add_nodes_from(cities.keys())

# Add edges (train connections)
connections = [("Paris", "Marseille"), ("Paris", "Lyon"), ("Paris", "Toulouse"), 
               ("Paris", "Nantes"), ("Paris", "Strasbourg"), ("Paris", "Lille"),
               ("Lyon", "Marseille"), ("Lyon", "Toulouse"), ("Lyon", "Strasbourg"),
               ("Marseille", "Nice"), ("Toulouse", "Nantes")]

G.add_edges_from(connections)
pos=list(cities.values())
# Draw the graph using latitude and longitude for positioning
nx.draw(G, cities, with_labels=True, node_size=2000, node_color="lightblue", font_size=10, font_color="black", font_weight="bold")
plt.title("Major Train Connections in France")
plt.show()
No description has been provided for this image
In [273]:
M=nx.adjacency_matrix(France).todense()
In [274]:
M.shape
Out[274]:
(8, 8)
In [281]:
row_sums = M.sum(axis=1)
P = M / row_sums[:, np.newaxis]
In [285]:
P
Out[285]:
array([[0.        , 0.16666667, 0.16666667, 0.16666667, 0.        ,
        0.16666667, 0.16666667, 0.16666667],
       [0.33333333, 0.        , 0.33333333, 0.        , 0.33333333,
        0.        , 0.        , 0.        ],
       [0.25      , 0.25      , 0.        , 0.25      , 0.        ,
        0.        , 0.25      , 0.        ],
       [0.33333333, 0.        , 0.33333333, 0.        , 0.        ,
        0.33333333, 0.        , 0.        ],
       [0.        , 1.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.5       , 0.        , 0.        , 0.5       , 0.        ,
        0.        , 0.        , 0.        ],
       [0.5       , 0.        , 0.5       , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [1.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ]])
In [290]:
nx.pagerank(France,alpha=1)
Out[290]:
{'Paris': 0.2727265178005436,
 'Marseille': 0.13636441767051125,
 'Lyon': 0.181817644890405,
 'Toulouse': 0.13636396006230836,
 'Nice': 0.04545420603234022,
 'Nantes': 0.09090911426768641,
 'Strasbourg': 0.09090942983697256,
 'Lille': 0.04545470943923175}